home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / inventor / SpaceballViewer / MyColorSlider.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.0 KB  |  160 lines

  1. /*
  2.  * Copyright (c) 1990-1992, 1994 Silicon Graphics, Inc.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that the name of Silicon Graphics may not be used in any advertising or
  7.  * publicity relating to the software without the specific, prior written
  8.  * permission of Silicon Graphics.
  9.  *
  10.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  11.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  12.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  13.  *
  14.  * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  15.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
  17.  * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  */
  20. //  -*- C++ -*-
  21.  
  22. /*
  23.  * Copyright (C) 1990,91,92   Silicon Graphics, Inc.
  24.  *
  25.  _______________________________________________________________________
  26.  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
  27.  |
  28.  |   $Revision: 1.1008 $
  29.  |
  30.  |   Description:
  31.  |    This file contains the MyColorSlider class which is an MySlider
  32.  |  (GL slider within an GLX widget) with build in policies. You can only
  33.  |  build a set of pre-defined color sliders (see Type enum below).
  34.  |
  35.  |   Classes:
  36.  |    MyColorSlider
  37.  |    
  38.  |   Author(s)    : Alain Dumesny
  39.  |
  40.  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
  41.  _______________________________________________________________________
  42.  */
  43.  
  44. #ifndef  _SO_XT_COLOR_SLIDER_
  45. #define  _SO_XT_COLOR_SLIDER_
  46.  
  47. #include "MySlider.h"
  48.  
  49. class SbColor;
  50. class SbVec2f;
  51.  
  52.  
  53. //////////////////////////////////////////////////////////////////////////////
  54. //
  55. //  Class: MyColorSlider
  56. //
  57. //    This class defines the color slider which is a set of predefined
  58. //  sliders (R, G, B, H, S, V,..) with special behaviors.
  59. //
  60. //////////////////////////////////////////////////////////////////////////////
  61.  
  62. // C-api: prefix=SoXtColSldr
  63. class MyColorSlider : public MySlider {
  64.     
  65.  public:
  66.     
  67.     //
  68.     // list of color sliders types
  69.     //
  70.     enum Type {
  71.     RED_SLIDER, 
  72.     GREEN_SLIDER, 
  73.     BLUE_SLIDER, 
  74.     HUE_SLIDER, 
  75.     SATURATION_SLIDER, 
  76.     VALUE_SLIDER, 
  77.     INTENSITY_SLIDER, // independent of the slider value
  78.     };
  79.     
  80.     // Constructor/Destructor
  81.     MyColorSlider(
  82.     Widget parent = NULL,
  83.     const char *name = NULL, 
  84.     SbBool buildInsideParent = TRUE, 
  85.     MyColorSlider::Type type = INTENSITY_SLIDER);
  86.     ~MyColorSlider();
  87.     
  88.     //
  89.     // Routine used to specify the slider value and also the top region
  90.     // color (WYSIWYGmode in most cases). Users should call this routine 
  91.     // instead of the base class setValue() routine if they want the color 
  92.     // slider top region to correctly reflect the current color.
  93.     // (code is optimized for WYSIWYGmode off)
  94.     //
  95.     // NOTE: routine expects
  96.     //        an rgb color for R, G or B slider type
  97.     //        an hsv color for H, S, or V slider type
  98.     //        an rgb color for Intensity slider type
  99.     //
  100.     // NOTE: if calling setBaseColor() changes the thumb position the
  101.     // valueChanged callbacks will be called with the new value.
  102.     //
  103.     // C-api: name=setBaseCol
  104.     void    setBaseColor(const float rgbOrHsv[3]);
  105.     // C-api: name=getBaseCol
  106.     const float *getBaseColor()         { return color; }
  107.     
  108.     //
  109.     // This routine sets the WYSIWYG (What You See Is What You Get) mode
  110.     // to be true or false (default FALSE). Immediate mode.
  111.     // This has no effect on monochrome sliders.
  112.     //
  113.     void    setWYSIWYG(SbBool trueOrFalse);    // default FALSE
  114.     SbBool      isWYSIWYG()             { return WYSIWYGmode; }
  115.     
  116.     // returns the type of the slider
  117.     MyColorSlider::Type getType()    { return type; }
  118.     
  119.   protected:
  120.  
  121.     // This constructor takes a boolean whether to build the widget now.
  122.     // Subclasses can pass FALSE, then call MySlider::buildWidget()
  123.     // when they are ready for it to be built.
  124.     SoEXTENDER
  125.     MyColorSlider(
  126.     Widget parent,
  127.     const char *name, 
  128.     SbBool buildInsideParent, 
  129.     MyColorSlider::Type type, 
  130.     SbBool buildNow);
  131.     
  132.     // redefine this routine to cache slider top geometry
  133.     virtual void    sizeChanged(const SbVec2s &newSize);
  134.     
  135.     // redefine this routine to do the actual slider top region drawing.
  136.     // This routine is automatically called by the MySlider::redraw() routine.
  137.     virtual void    drawSliderTopRegion();
  138.     
  139.   private:
  140.     
  141.     // local vars
  142.     Boolean        WYSIWYGmode;
  143.     Type        type;
  144.     float        color[3];
  145.     SbColor        *defaultColors, *colors;
  146.     SbVec2f        *geometry;
  147.     
  148.     // routine that make the default and WYSIWYG colors
  149.     void    makeDefaultColors();
  150.     void    makeWYSIWYGcolors();
  151.     
  152.     static void        sliderChangedCB(void *, float val);
  153.  
  154.     // this is called by both constructors
  155.     void constructorCommon(MyColorSlider::Type type, SbBool buildNow);
  156. };
  157.  
  158.  
  159. #endif  /* _SO_XT_COLOR_SLIDER_ */
  160.